home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / EMULATOR / GBDK_BIN / examples / c / test < prev   
Text File  |  1997-01-09  |  2KB  |  132 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <graphics.h>
  4. #include "fish.h"
  5.  
  6. void main()
  7. {
  8.   char s[16];
  9.   int i, j, k;
  10.  
  11.   puts("A: text demo");
  12.   puts("B: graphic demo");
  13.   puts("START: picture");
  14.  
  15.   i = waitpad(J_A | J_B | J_START);
  16.   waitpadup();
  17.  
  18.   if(i == J_A) {
  19.     int i1, i2, i3;
  20.  
  21.     printf("Hello %s\n", "World");
  22.     strcpy(s, "Hello World!");
  23.     reverse(s);
  24.     puts(s);
  25.  
  26.     for(i = 0; i <= 0x10; i++) {
  27.       printn(i, 16);
  28.       putchar(' ');
  29.     }
  30.     putchar(EOL);
  31.  
  32.     for(i = 0; i < 3; i++) {
  33.       switch(i)
  34.         {
  35.         case 0:
  36.           printn(0, 10);
  37.           break;
  38.         case 1:
  39.           printn(1, 10);
  40.           break;
  41.         case 2:
  42.           printn(2, 10);
  43.           break;
  44.         default:
  45.           print("Error");
  46.           break;
  47.         }
  48.       putchar(' ');
  49.     }
  50.     putchar(EOL);
  51.  
  52.     printf("Numbers: %c %d %o %x\n", 'A', 13, 13, 13);
  53.     printf("Enter 3 nb:");
  54.     i = scanf("%d %x %o", &i1, &i2, &i3);
  55.     printf("Result: %d %d %d %d\n", i, i1, i2, i3);
  56.  
  57.     itoa(abs(-234), s);
  58.     puts(s);
  59.     itoa(-234, s);
  60.     puts(s);
  61.     itoa(atoi(s), s);
  62.     puts(s);
  63.  
  64.     strcpy(s, "Hello");
  65.     strcat(s, " World!");
  66.     puts(s);
  67.  
  68.     printn(strlen(s), 10);
  69.     putchar(EOL);
  70.  
  71.     printn(strcmp(s, "Hello Earth!"), 10);
  72.     putchar(' ');
  73.     printn(strcmp(s, "Hello World!"), 10);
  74.     putchar(' ');
  75.     printn(strcmp(s, "Hi World!"), 10);
  76.     putchar(EOL);
  77.  
  78.     printf("Enter nb: ");
  79.     puts(gets(s));
  80.     printf("2 * ");
  81.     print(s);
  82.     printf(" = ");
  83.     puts(itoa(atoi(s) * 2, s));
  84.  
  85.     printf("End of program");
  86.   } else if(i == J_B) {
  87.     int m = OR;
  88.     int c = BLACK;
  89.  
  90.     i = 50;
  91.     j = 50;
  92.     k = 0;
  93.  
  94.     while(1) {
  95.       if(i >= 0 && i <= 0x7F && j >= 0 && j <= 0x77)
  96.         plot(i, j, c, m);
  97.       else {
  98.         i = i < 0 ? 0 : i;
  99.         j = j < 0 ? 0 : j;
  100.         i = i > 0x7F ? 0x7F : i;
  101.         j = j > 0x77 ? 0x77 : j;
  102.       }
  103.  
  104.       k = waitpad(J_UP | J_DOWN | J_LEFT | J_RIGHT | J_A | J_B | J_START);
  105.  
  106.       if(k & J_START) {
  107.         break;
  108.       }
  109.       if(k & J_A) {
  110.         m = ++m % 4;
  111.         waitpadup();
  112.       }
  113.       if(k & J_B) {
  114.         c = ++c % 4;
  115.         waitpadup();
  116.       }
  117.       if(k & J_UP)
  118.         j--;
  119.       if(k & J_DOWN)
  120.         j++;
  121.       if(k & J_LEFT)
  122.         i--;
  123.       if(k & J_RIGHT)
  124.         i++;
  125.       delay(500);
  126.     }
  127.   } else {
  128.     draw_image(fish_data);
  129.     waitpad(J_START);
  130.   }
  131. }
  132.